package com.jmb.api.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.annotate.PageParams;
import com.jmb.api.common.result.Result;
import com.jmb.api.dto.PageParam.PageParam;
import com.jmb.api.dto.system.HttpSettingDTO;
import com.jmb.api.service.HttpSettingService;
import com.jmb.api.vo.system.HttpSettingVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Tag(name = "代理配置")
@RequestMapping("system")
@RestController
public class HttpSettingController {
    @Autowired
    private HttpSettingService httpSettingService;

    @Operation(summary = "新增代理配置")
    @PostMapping("setting/save")
    public Result save(@RequestBody @Valid HttpSettingDTO httpSettingDTO) {
        httpSettingService.saveHtppSetting(httpSettingDTO);
        return Result.ok();
    }
    @Operation(summary = "代理配置列表")
    @GetMapping("setting/list")
    public Result<IPage<HttpSettingDTO>> list(PageParam pageParam, HttpSettingVo httpSettingVo) {
        IPage<HttpSettingDTO> page = new Page<>(pageParam.getPageNum(),pageParam.getPageSize());
        IPage<HttpSettingDTO> list = httpSettingService.getListHttpSetting(page,httpSettingVo);
        return Result.ok(list);
    }
    @Operation(summary = "修改代理配置")
    @PostMapping("setting/modify")
    public Result modify(@RequestBody @Valid HttpSettingDTO httpSettingDTO) {
        httpSettingService.updateHttpSetting(httpSettingDTO);
        return Result.ok();
    }

    @Operation(summary = "删除代理配置")
    @GetMapping("setting/remove")
    public Result remove(@RequestParam Integer settingId) {
        httpSettingService.removeById(settingId);
        return Result.ok();
    }
    @Operation(summary = "修改代理配置状态")
    @PostMapping("setting/modify/status")
    public Result modifyStatusId(@RequestParam Integer settingId,@RequestParam Integer statusId) {
        httpSettingService.updateStatusId(settingId,statusId);
        return Result.ok();
    }
}
